package com.netease.qa.web.utils;

import com.netease.qa.biz.dto.UserDTO;
import com.netease.qa.biz.service.TeamService;
import com.netease.qa.biz.service.impl.TeamServiceImpl;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author zoudongdong
 * @date 2018/3/8
 */
@Component
public class UserUtils {

    private static TeamService teamService;

    public TeamService getTeamService() {
        return teamService;
    }

    @Resource
    public void setTeamService(TeamService teamService) {
        UserUtils.teamService = teamService;
    }

    //获得当前登录的用户userId
    public static String getCurrentLoginUserId(HttpServletRequest request) {
        HttpSession session = request.getSession();
        UserDTO userDTO = (UserDTO) session.getAttribute("loginUser");
        return userDTO.getUserId();
    }

    //判断当前登录用户是否属于当前组
    public static boolean ifUserJoinedTeam(String currentUserId, int teamId) {
        List<String> joinedUserIdList = teamService.getJoinedUserIdList(teamId);
        if (!joinedUserIdList.contains(currentUserId)) {
            return false;
        }
        return true;
    }

}
